package com.yjj.demo.starter;

import com.yjj.demo.common.interceptor.ApiLimiterInterceptor;
import com.yjj.demo.common.interceptor.QPSLimiterInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *
 *
 * @author yangjiajia
 * @createdAt 2023/1/19 11:04
 */
@Configuration
public class WebConfiguration implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getApiLimiterInterceptor());
        registry.addInterceptor(getQPSLimiterInterceptor());
    }

    @Bean
    public ApiLimiterInterceptor getApiLimiterInterceptor() {
        return new ApiLimiterInterceptor();
    }

    @Bean
    public QPSLimiterInterceptor getQPSLimiterInterceptor() {
        return new QPSLimiterInterceptor();
    }
}
